package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.ElectricalWellCreateReqDTO;
import com.huaxin.device.dto.request.ElectricalWellPageListReqDTO;
import com.huaxin.device.dto.request.ElectricalWellUpdateReqDTO;
import com.huaxin.device.models.ElectricalWell;
import com.huaxin.device.service.ElectricalWellService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "电井信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/electricalWell")
public class ElectricalWellController {

    private final ElectricalWellService service;

    @Operation(summary = "创建电井", description = "创建电井信息")
    @PostMapping("/create")
    public ResponseResult<ElectricalWell> create(@RequestBody @Valid ElectricalWellCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取电井", description = "根据ID获取电井信息")
    @GetMapping("/get")
    public ResponseResult<ElectricalWell> get(
            @Parameter(description = "电井ID", example = "well_001")
            @RequestParam("id") String id) {
        ElectricalWell entity = service.getByWellId(id);
        return ResponseResult.ok(entity);
    }

    @Operation(summary = "更新电井", description = "更新电井信息")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid ElectricalWellUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除电井", description = "删除电井（软删除或物理删除依据业务）")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(@PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "分页查询电井", description = "支持名称、编号、位置等条件分页查询")
    @PostMapping("/page")
    public ResponseResult<IPage<ElectricalWell>> pageQuery(@RequestBody @Valid ElectricalWellPageListReqDTO in) {
        return service.pageQuery(in);
    }
}